<?php
ini_set('date.timezone','Asia/Shanghai');
require_once '../../application/libraries/aliyun-dysms-php-sdk/api_demo/SmsDemo.php'; //这个是实例化的类
require_once '../../application/libraries/JssdkLogic.php';
require_once "../lib/WxPay.Api.php";
require_once '../lib/WxPay.Notify.php';
require_once 'log.php';
	
class qitian extends WxPayNotify
{
	
	//查询订单 ReplyNotify
	public function qitiantaocan()
	{ 
			echo 2222;die;
			$hostname = WxPayConfig::HOST;
			$username = WxPayConfig::USERNAME;
			$password = WxPayConfig::PASSWORDE;
			$database = WxPayConfig::DATABASSE;
				
			$id = WxPayConfig::ID;
			$signkey = WxPayConfig::SIGNKEY;
			
			$con = mysql_connect($hostname,$username,$password);
			if (!$con)
			{
				die('Could not connect: ' . mysql_error());
			}
			$device_id = $_GET['device_id'];
			print_r($device_id);die;
			mysql_select_db($database, $con);
			
			$device_sql = "SELECT * FROM mifi_device WHERE device_sn = ".$device_id."";
			$device_result = mysql_query($device_sql);
			$device = mysql_fetch_array($device_result);

			//充值
			if($device['experience'] == 0){

				//体验订单
				$data['order_on'] = time().rand(100,999); //订单编号
				$data['starttime'] = date("YmdHis"); //下单时间
				$data['endtime'] = date("YmdHis"); //下单时间
				$data['paystate'] = '1';      //支付状态 0未支付  1已支付  
				$data['goods_on'] = '28'; //套餐
				$data['user_id'] = '0';
				$data['device_id'] = $device_id;
				$data['order_money'] = '20';
				
				$sql_into = "INSERT INTO `mifi_order` (`order_on`, `starttime`, `endtime`, `paystate`, `goods_on`, `user_id`, `device_id`,`order_money`) VALUES ('".$data['order_on']."', '".$data['starttime']."', '".$data['endtime']."','".$data['paystate']."','".$data['goods_on']."', '".$data['user_id']."', '".$data['device_id']."', '".$data['order_money']."')";
				$result_into = mysql_query($sql_into);
				
				
				$device_recharge = WxPayApi::device_recharge($device_id,$data['order_on'],'28');
				

				//修改设备状态
				$experience_sql = "UPDATE `mifi_device` SET `experience`='1',`experience_time`='".$data['endtime']."' WHERE (`device_sn`='".$device_id."')";
				$experience_result = mysql_query($experience_sql);

				print_r('开通7天体验成功！！');die;
			}else{
				print_r('设备已开通7天体验！');die;
			}
		
	}
	
	public function taocan()
	{ 		
	
			/* //微信推送
			$appid = WxPayConfig::APPID;
			$secret = WxPayConfig::APPSECRET;
			
			$hostname = WxPayConfig::HOST;
			$username = WxPayConfig::USERNAME;
			$password = WxPayConfig::PASSWORDE;
			$database = WxPayConfig::DATABASSE;
				
		
			$id = WxPayConfig::ID;
			$signkey = WxPayConfig::SIGNKEY;
			
			$con = mysql_connect($hostname,$username,$password);
			if (!$con)
			{
				die('Could not connect: ' . mysql_error());
			}
			mysql_select_db($database, $con);	
			
			//拿到用户微信
			$user_sql_wx = "SELECT * FROM mifi_users_weixin WHERE user_id = 64";
			$user_result_wx = mysql_query($user_sql_wx);
			$user_wx = mysql_fetch_array($user_result_wx);
			
			$JssdkLogic = new JssdkLogic($appid,$secret);
			$data = $JssdkLogic->push_msg($user_wx['openid'],'您的设备充值成功！');
			print_r($data);die; */
	
			/* $device_recharge = WxPayApi::device_recharge('866666030862321','1517978680222','2');
			print_r($device_recharge);
			if($device_recharge['result'] == 0){
					print_r('充值成功！！');
			}
			die; */
	}
}

$input = new qitian();
$input->taocan();
